package com.cbtx.networklib.cookie

import okhttp3.Cookie
import okhttp3.CookieJar
import okhttp3.HttpUrl

/**
 * author : joker.peng
 * e-mail : joker@fiture.com
 * date   : 2021/6/29 12:57 PM
 * desc   :
 */
class CookieJarImpl : CookieJar {

    var cookieStore: CookieStore

    constructor(cookieStore: CookieStore) {
        this.cookieStore = cookieStore
    }

    @Synchronized
    override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
        cookieStore.saveCookie(url, cookies)
    }

    @Synchronized
    override fun loadForRequest(url: HttpUrl): List<Cookie> {
        return cookieStore.loadCookie(url)
    }
}